<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
</head>
<body>
    <div class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'center',border:false">
            <table id="dg_20200506lygl"></table>
        </div>
    </div>

    <div id="mm_20200605" class="easyui-menu" style="width:120px;display: none;">
        <div data-options="iconCls:'icon-ok',id:'m-add-20200605'">添加</div>
        <div data-options="id:'m-update-20200605'">修改</div>
        <div data-options="id:'m-start-20200605'">启用</div>
        <div data-options="id:'m-stop-20200605'">停用</div>
    </div>

<script>
    $(function(){
        $('#dg_20200506lygl').datagrid({
            url: './../userinfo/queryUserinfoAll',
            method: 'get',
            border: false,
            fit: true,
            fitColumns: true,
            scrollbarSize: 2, //滚动条宽度
            striped: true,
            rownumbers: true,
            pagination: true,
            singleSelect: true,
            sortName: 'id',   //定义排序的列名
            sortOrder: 'desc',   //'asc' 或 'desc'。
            nowrap:false, //设置为 true，则把数据显示在一行里。设置为 true 可提高加载性能。
            fixRowHeight:'100px',
            columns:[[
                {field:'id',title:'ID',width:100,hidden:true},
                {field:'username',title:'登录账号',width:100},
                {field:'name',title:'姓名',width:100},
                {field:'lastLoginTime',title:'最后登录时间',width:100,
                    formatter: function(value,row,index) {
                        let json_date = new Date(value).toJSON();
                        return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
                    }
                },
                {field:'createTime',title:'创建时间',width:200},
                {field:'status',title:'状态',width:100,
                    // styler:function (value,row,index) {
                    //     return 'height:80px';
                    // },
                    formatter: function(value,row,index){
                        if(value == 0){
                            return '<span class="easyui-dot easyui-status-error"></span> 停用';
                        }else if(value == 1){
                            return '<span class="easyui-dot easyui-status-processing"></span> 正常';
                        }else {
                            return '<span class="easyui-dot easyui-status-success"></span> 未知';
                        }
                    }
                }
            ]],
            onHeaderContextMenu: function(e, field){
                e.preventDefault();
                $(this).datagrid('columnMenu').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                });
            },
            onRowContextMenu: function(e,index,row) {
                e.preventDefault();
                $(this).datagrid('unselectAll');

                let update = $('#m-update-20200605')[0];
                let start = $('#m-start-20200605')[0];
                let stop = $('#m-stop-20200605')[0];

                if(!row){
                    $('#mm_20200605').menu('hideItem', update).menu('hideItem', start).menu('hideItem', stop);
                }else{
                    $('#mm_20200605').menu('showItem', update).menu('showItem', start).menu('showItem', stop);
                    $(this).datagrid('selectRow', index);
                }

                $(this).datagrid('selectRow', index);
                $('#mm_20200605').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                });
            }
        })

        //鼠标右击菜单
        $('#mm_20200605').menu({
            onClick:function(item){
                let rowData = $('#dg_20200506lygl').datagrid('getSelected');
                let state = 0;
                if(item.id == 'm-update-20200605'){
                    state = 2;
                }
                console.log(rowData.id,123,state)
                $.ajax({
                    type: "POST",
                    url: "./../comment/updateCoent",
                    data: {id:rowData.id,state:state},
                    success: function(json){
                      //  let data = eval('(' + json + ')');
                        if(json.code == 200){
                            new jBox('Notice', {
                                color: 'green',
                                autoClose: 2500,
                                content: ' 操作成功。',
                                showCountdown: true,
                                animation: 'slide'
                            });
                            $('#dg_20200506lygl').datagrid('reload');
                        }else{
                            new jBox('Notice', {
                                color: 'red',
                                autoClose: 2500,
                                content: '操作失败！',
                                showCountdown: true,
                                animation: 'slide'
                            });
                        }
                    }
                });
            }
        });
    });
</script>
</body>
</html>